<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\Database\Model\Relations\BelongsTo;
use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\Database\Model\SoftDeletes;

/**
 * @property int $id 
 * @property int $user_id
 * @property string $order_no 
 * @property int $order_type 
 * @property float $total_price 
 * @property float $discount_price 
 * @property float $price 
 * @property int $integral 
 * @property int $status
 * @property string $remark
 * @property int $pay_type
 * @property int $pay_time 
 * @property int $ship_time 
 * @property int $complete_time 
 * @property int $refund_time 
 * @property string $express_name 
 * @property string $express_phone 
 * @property string $express_address 
 * @property string $express_zip_code
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property int $deleted_at
 * @property OrderItem $items
 */
class Order extends Model
{
    use SoftDeletes;

    public $dateFormat = 'U';

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'order';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $guarded = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'int', 'user_id' => 'integer', 'buy_type' => 'integer', 'order_type' => 'integer', 'total_price' => 'float', 'discount_price' => 'float', 'price' => 'float', 'integral' => 'integer', 'status' => 'integer', 'pay_type' => 'integer', 'pay_time' => 'integer', 'ship_time' => 'integer', 'complete_time' => 'integer', 'refund_time' => 'integer', 'created_at' => 'integer', 'updated_at' => 'integer', 'deleted_at' => 'integer'];

    /**
     * hidden
     *
     * @var array
     */
    public $hidden = ['updated_at', 'deleted_at'];

    /**
     * 用户关联模型
     *
     * @return BelongsTo
     */
    public function user() :BelongsTo
    {
        return $this->belongsTo(User::class, 'id', 'user_id');
    }

    /**
     * 订单项关联
     *
     * @return HasMany
     */
    public function items() :HasMany
    {
        return $this->hasMany(OrderItem::class, 'order_no', 'order_no');
    }
}